```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>算法可视化：插入排序与优化</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
        }
        .code-block {
            background-color: #1e293b;
            border-left: 4px solid #8b5cf6;
        }
        .algorithm-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .time-complexity {
            background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
        }
        .insert-animation {
            transition: all 0.3s ease;
        }
        .highlight {
            background-color: #fef3c7;
            padding: 0.2rem 0.4rem;
            border-radius: 0.25rem;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 font-serif">插入排序与优化</h1>
                    <p class="text-xl md:text-2xl opacity-90 mb-8 font-serif">探索经典排序算法的核心思想与性能优化</p>
                    <div class="flex space-x-4">
                        <div class="bg-white bg-opacity-20 rounded-full px-6 py-3 font-medium hover:bg-opacity-30 transition cursor-pointer">
                            <i class="fas fa-play-circle mr-2"></i> 可视化演示
                        </div>
                        <div class="border border-white border-opacity-30 rounded-full px-6 py-3 font-medium hover:bg-white hover:bg-opacity-10 transition cursor-pointer">
                            <i class="fas fa-code mr-2"></i> 查看代码
                        </div>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative w-full max-w-md">
                        <div class="absolute inset-0 bg-purple-500 rounded-xl opacity-20 blur-2xl"></div>
                        <div class="relative bg-white bg-opacity-10 backdrop-blur-sm rounded-xl p-6 border border-white border-opacity-20">
                            <div class="flex justify-between mb-4">
                                <div class="text-sm font-mono">[5, 2, 4, 6, 1, 3]</div>
                                <div class="text-xs opacity-70">原始数组</div>
                            </div>
                            <div class="space-y-2">
                                <div class="flex items-center space-x-2">
                                    <div class="w-8 h-8 rounded-lg bg-pink-500 flex items-center justify-center text-white font-bold">1</div>
                                    <div class="text-sm">i=1: 2插入到5前</div>
                                </div>
                                <div class="flex items-center space-x-2">
                                    <div class="w-8 h-8 rounded-lg bg-indigo-500 flex items-center justify-center text-white font-bold">2</div>
                                    <div class="text-sm">i=2: 4插入到2和5之间</div>
                                </div>
                                <div class="flex items-center space-x-2 opacity-70">
                                    <div class="w-8 h-8 rounded-lg flex items-center justify-center">3</div>
                                    <div class="text-sm">i=3: 6已在正确位置</div>
                                </div>
                                <div class="flex items-center space-x-2 opacity-70">
                                    <div class="w-8 h-8 rounded-lg flex items-center justify-center">4</div>
                                    <div class="text-sm">i=4: 1插入到最前</div>
                                </div>
                                <div class="flex items-center space-x-2 opacity-70">
                                    <div class="w-8 h-8 rounded-lg flex items-center justify-center">5</div>
                                    <div class="text-sm">i=5: 3插入到1,2,4之间</div>
                                </div>
                            </div>
                            <div class="mt-6 pt-4 border-t border-white border-opacity-20">
                                <div class="flex justify-between">
                                    <div class="text-sm font-mono">[1, 2, 3, 4, 5, 6]</div>
                                    <div class="text-xs opacity-70">排序完成</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-6xl px-4 py-16">
        <!-- Algorithm Overview -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 font-serif text-gray-800 flex items-center">
                <i class="fas fa-sort-amount-down-alt mr-4 text-indigo-500"></i>
                算法概述
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="algorithm-card bg-white rounded-2xl shadow-lg overflow-hidden transition duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600 mr-4">
                                <i class="fas fa-sort-numeric-up text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">基本插入排序</h3>
                        </div>
                        <p class="text-gray-600 mb-4">将数组分为<span class="highlight">已排序</span>和<span class="highlight">未排序</span>两部分，逐个将未排序元素插入到已排序部分的正确位置。</p>
                        
                        <div class="time-complexity p-4 rounded-lg mb-4">
                            <div class="flex justify-between items-center">
                                <div>
                                    <h4 class="font-medium text-gray-700">时间复杂度</h4>
                                    <div class="text-2xl font-bold text-indigo-600">O(n²)</div>
                                </div>
                                <div>
                                    <h4 class="font-medium text-gray-700">空间复杂度</h4>
                                    <div class="text-2xl font-bold text-indigo-600">O(1)</div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="flex space-x-2">
                            <div class="text-xs px-2 py-1 bg-indigo-100 text-indigo-700 rounded-full">原地排序</div>
                            <div class="text-xs px-2 py-1 bg-indigo-100 text-indigo-700 rounded-full">稳定排序</div>
                            <div class="text-xs px-2 py-1 bg-indigo-100 text-indigo-700 rounded-full">适合小规模数据</div>
                        </div>
                    </div>
                </div>
                
                <div class="algorithm-card bg-white rounded-2xl shadow-lg overflow-hidden transition duration-300">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center text-purple-600 mr-4">
                                <i class="fas fa-search-plus text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">二分查找优化</h3>
                        </div>
                        <p class="text-gray-600 mb-4">通过<span class="highlight">二分查找</span>确定插入位置，减少比较次数，但元素移动次数不变，整体时间复杂度仍为O(n²)。</p>
                        
                        <div class="time-complexity p-4 rounded-lg mb-4">
                            <div class="flex justify-between items-center">
                                <div>
                                    <h4 class="font-medium text-gray-700">比较次数</h4>
                                    <div class="text-2xl font-bold text-purple-600">O(n log n)</div>
                                </div>
                                <div>
                                    <h4 class="font-medium text-gray-700">移动次数</h4>
                                    <div class="text-2xl font-bold text-purple-600">O(n²)</div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="flex space-x-2">
                            <div class="text-xs px-2 py-1 bg-purple-100 text-purple-700 rounded-full">减少比较</div>
                            <div class="text-xs px-2 py-1 bg-purple-100 text-purple-700 rounded-full">适合部分有序</div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 font-serif text-gray-800 flex items-center">
                <i class="fas fa-project-diagram mr-4 text-indigo-500"></i>
                算法可视化
            </h2>
            
            <div class="bg-white rounded-2xl shadow-lg overflow-hidden">
                <div class="p-6">
                    <div class="mermaid">
                        graph LR
                            A[未排序数组] --> B[分为已排序和未排序部分]
                            B --> C[取第一个未排序元素]
                            C --> D[在已排序部分中找到插入位置]
                            D --> E[移动元素并插入]
                            E --> F{是否还有未排序元素?}
                            F -->|是| C
                            F -->|否| G[排序完成]
                    </div>
                    
                    <div class="mt-8 grid md:grid-cols-3 gap-4 text-center">
                        <div class="p-4 border border-gray-100 rounded-lg insert-animation hover:bg-indigo-50">
                            <div class="text-4xl text-indigo-500 mb-2"><i class="fas fa-exchange-alt"></i></div>
                            <h4 class="font-bold mb-1">元素比较</h4>
                            <p class="text-sm text-gray-600">逐个比较确定插入位置</p>
                        </div>
                        <div class="p-4 border border-gray-100 rounded-lg insert-animation hover:bg-purple-50">
                            <div class="text-4xl text-purple-500 mb-2"><i class="fas fa-search"></i></div>
                            <h4 class="font-bold mb-1">二分优化</h4>
                            <p class="text-sm text-gray-600">二分查找减少比较次数</p>
                        </div>
                        <div class="p-4 border border-gray-100 rounded-lg insert-animation hover:bg-pink-50">
                            <div class="text-4xl text-pink-500 mb-2"><i class="fas fa-arrows-alt-h"></i></div>
                            <h4 class="font-bold mb-1">元素移动</h4>
                            <p class="text-sm text-gray-600">向后移动元素腾出位置</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Implementation -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 font-serif text-gray-800 flex items-center">
                <i class="fas fa-code mr-4 text-indigo-500"></i>
                代码实现
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600 mr-3">
                            <i class="fas fa-sort-amount-down"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">基础版本</h3>
                    </div>
                    
                    <div class="code-block rounded-lg overflow-hidden mb-6">
                        <div class="px-4 py-2 bg-gray-800 text-gray-300 flex justify-between items-center">
                            <div class="text-sm">Python</div>
                            <button class="text-gray-400 hover:text-white">
                                <i class="far fa-copy"></i>
                            </button>
                        </div>
                        <pre class="p-4 text-gray-200 overflow-x-auto"><code>
def insertionSort(nums):
    for i in range(1, len(nums)):
        key = nums[i]
        j = i - 1
        while j >= 0 and nums[j] > key:
            nums[j + 1] = nums[j]
            j -= 1
        nums[j + 1] = key
    return nums
                        </code></pre>
                    </div>
                    
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-100">
                        <div class="flex items-start">
                            <div class="text-blue-500 mr-3 mt-1"><i class="fas fa-info-circle"></i></div>
                            <div>
                                <h4 class="font-bold text-blue-800 mb-1">工作原理</h4>
                                <p class="text-sm text-blue-700">外层循环遍历每个元素，内层循环将当前元素与已排序部分比较并插入正确位置。</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center text-purple-600 mr-3">
                            <i class="fas fa-bolt"></i>
                        </div>
                        <h3 class="text-xl font-bold text-gray-800">优化版本</h3>
                    </div>
                    
                    <div class="code-block rounded-lg overflow-hidden mb-6">
                        <div class="px-4 py-2 bg-gray-800 text-gray-300 flex justify-between items-center">
                            <div class="text-sm">Python</div>
                            <button class="text-gray-400 hover:text-white">
                                <i class="far fa-copy"></i>
                            </button>
                        </div>
                        <pre class="p-4 text-gray-200 overflow-x-auto"><code>
def binaryInsertionSort(nums):
    for i in range(1, len(nums)):
        key = nums[i]
        left, right = 0, i - 1
        while left <= right:
            mid = (left + right) // 2
            if nums[mid] < key:
                left = mid + 1
            else:
                right = mid - 1
        for j in range(i, left, -1):
            nums[j] = nums[j - 1]
        nums[left] = key
    return nums
                        </code></pre>
                    </div>
                    
                    <div class="bg-purple-50 p-4 rounded-lg border border-purple-100">
                        <div class="flex items-start">
                            <div class="text-purple-500 mr-3 mt-1"><i class="fas fa-lightbulb"></i></div>
                            <div>
                                <h4 class="font-bold text-purple-800 mb-1">优化点</h4>
                                <p class="text-sm text-purple-700">使用二分查找确定插入位置，将比较次数从O(n)降为O(log n)，但元素移动次数仍为O(n²)。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Analysis -->
        <section>
            <h2 class="text-3xl font-bold mb-8 font-serif text-gray-800 flex items-center">
                <i class="fas fa-chart-line mr-4 text-indigo-500"></i>
                性能分析
            </h2>
            
            <div class="bg-white rounded-2xl shadow-lg overflow-hidden">
                <div class="p-6">
                    <div class="mermaid">
                        xychart-beta
                            title "插入排序时间复杂度比较"
                            x-axis [最佳情况, 平均情况, 最坏情况]
                            y-axis "时间复杂度" 0 --> 100
                            bar [O(n), O(n²), O(n²)] --> "基本插入排序"
                            bar [O(n log n), O(n²), O(n²)] --> "优化版本"
                    </div>
                    
                    <div class="mt-8 grid md:grid-cols-3 gap-6">
                        <div class="bg-white p-6 rounded-xl border border-gray-100 shadow-sm">
                            <div class="text-indigo-500 text-3xl mb-4"><i class="fas fa-battery-three-quarters"></i></div>
                            <h4 class="font-bold text-lg mb-2">最佳情况</h4>
                            <p class="text-gray-600">当输入数组已经有序时，基本版本只需O(n)次比较，优化版本只需O(n log n)次比较。</p>
                        </div>
                        <div class="bg-white p-6 rounded-xl border border-gray-100 shadow-sm">
                            <div class="text-purple-500 text-3xl mb-4"><i class="fas fa-balance-scale"></i></div>
                            <h4 class="font-bold text-lg mb-2">平均情况</h4>
                            <p class="text-gray-600">对于随机数据，两种版本都需要O(n²)时间，但优化版本比较次数显著减少。</p>
                        </div>
                        <div class="bg-white p-6 rounded-xl border border-gray-100 shadow-sm">
                            <div class="text-pink-500 text-3xl mb-4"><i class="fas fa-exclamation-triangle"></i></div>
                            <h4 class="font-bold text-lg mb-2">最坏情况</h4>
                            <p class="text-gray-600">当输入数组逆序时，两种版本都需要O(n²)时间，且优化优势不明显。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            fontFamily: 'Noto Sans SC, sans-serif'
        });
        
        // 微交互效果
        document.querySelectorAll('.algorithm-card').forEach(card => {
            card.addEventListener('mouseenter', () => {
                const icon = card.querySelector('i');
                icon.classList.add('animate-bounce');
            });
            card.addEventListener('mouseleave', () => {
                const icon = card.querySelector('i');
                icon.classList.remove('animate-bounce');
            });
        });
    </script>
</body>
</html>
```